<template>
	<view class="container-gray">
		<template v-if="parseInt(examType) == 4">
			<view class="head" v-for="(item, index) in dataList" :key="index" @click="goTopic(item)">
				<view class="exam-title" style="line-height: 90upx;">{{ item.examName }}</view>
			</view>
		</template>
		<template v-else>
			<view class="head" v-for="(item, index) in dataList" @click="goTopic(item)" :key="index">
				<view class="exam-title">{{ item.examName }}</view>
				<view class="info-text">{{ item.submitPaperTime }}，共{{ item.totalQuesCount }}题，做错{{ item.errorQuesCount }}题</view>
			</view>
		</template>
	</view>
</template>

<script>
import { post_md5 } from './../../common/request';
import { setNavTitle } from './../../common/common';

export default {
	data() {
		return {
			examType: 0,
			dataList: []
		};
	},
	onLoad(options) {
		let title = '';
		if (options.examType == '1') {
			title = '正式考试';
		} else if (options.examType == '2') {
			title = '模拟考试';
		} else if (options.examType == '3') {
			title = '三违考试';
		} else {
			title = '专业提升';
		}
		setNavTitle('错题-' + title);
		this.examType = options.examType;
	},
	onShow() {
		if (this.examType == '5') {
			this.getQuesList();
		} else {
			this.getList();
		}
	},
	methods: {
		// 获取对应分类的考试记录
		getList() {
			const params = {
				userId: uni.getStorageSync('userId'),
				errorType: this.examType
			};
			post_md5('/exam-app/error/examlist', params).then(res => {
				console.log(res);
				this.dataList = res.data;
			});
		},

		getQuesList() {
			const params = {
				userId: uni.getStorageSync('userId')
			};
			post_md5('/exam/getQuesListByUserId', params).then(res => {
				this.dataList = res.data;
			});
		},

		// 查看错题
		goTopic(item) {
			uni.navigateTo({
				url: 'mistake-topic?examType=' + this.examType + '&examId=' + item.examId + '&examScoreId=' + item.examScoreId + '&quesCateId=' + item.id
			});
		}
	}
};
</script>

<style>
.head {
	padding: 30upx;
	margin-top: 1px;
}

.exam-title {
	font-size: 30upx;
	color: #333333;
	font-weight: 600;
	margin-top: 1px;
}

.info-text {
	font-size: 24upx;
	color: #999999;
	margin-top: 18upx;
}
</style>
